/************************************************
 *** Datei: DroneSwarmController.h
 ***
 *** Erstellt am: 17.05.2012
 ***       Autor: Max Stark <Max.Stark88@googlemail.com>
 ***	 Version: 1.0
 ***	
 *** Beschreibung:
 *** <hier Beschreibung einfuegen>
 ************************************************/

#ifndef DRONESWARMCONTROLLER_H_
#define DRONESWARMCONTROLLER_H_


#include <boost/thread.hpp>
using namespace boost;
//#include <vector>
//#include <string>
//using namespace std;

#include "../model/IDrone.h"
#include "../view/UIController.h"
#include "DroneController.h"
#include "DroneNetController.h"

#define DRONELIST_MAX_TTL 4

struct DroneListEntry {
	string strDroneHostName;
	string strDroneModelName;
	string strIPAddress;
	bool masterDrone;
	bool slaveDrone;
	unsigned int TTL;
};

class DroneSwarmController {
	IDrone* 			drone;
	DroneController* 	droneController;
	DroneNetController* droneNetController;
	UIController* 		uiController;

	bool isRunning;
	void init();

	thread* checkDroneListThread;
	bool 	checkDroneListThread_Active;
	void 	checkDroneList();

	vector<DroneListEntry>* droneList;
	mutex droneListMutex;

	//enum DroneControlMode {MANUELL, AUTO};
	//int droneControlMode;

public:
	DroneSwarmController();
	DroneSwarmController(IDrone* drone);
	virtual ~DroneSwarmController();

	void run();
	void stop();

	void insertIntoDroneList(DroneListEntry drone);
	void updateDroneList_Slave(string ipAddress, bool slave);
	void updateDroneList_Master(string ipAddress, bool master);
	void sendMasterMessage(int index);

	IDrone* getDrone() { return this->drone; }
	//void setDrone(IDrone* drone);

	//int getDroneControlMode() {return this->droneControlMode; }
	//void setDroneControlMode(DroneControlMode droneControlMode);

	vector<DroneListEntry>*		getDroneList();
	DroneController* 			getDroneController() { return this->droneController; }
	DroneNetController* 		getDroneNetController() { return this->droneNetController; }
	UIController* 				getUIController() { return this->uiController; }

	// Das Attribut speichert die IP-Adresse der aktuellen Master-
	// Drohne, um schnell darauf zugreifen zu koennen. (ohne ueber die
	// Liste zu iterieren)
	string actMasterDroneIPAddress;
};

#endif /* DRONESWARMCONTROLLER_H_ */
